package com.example.controller;

import com.example.common.Result;
import com.example.entity.Account;
import com.example.service.admin.AdminLoginService;
import com.example.service.student.StudentLoginService;
import com.example.service.teacher.TeacherLoginService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录
 */


@RestController
public class LoginController {
    @Resource
    private StudentLoginService studentLoginService;

    @Resource
    private TeacherLoginService teacherLoginService;

    @Resource
    private AdminLoginService adminLoginService;

    @PostMapping("/login")
    public Result login(@RequestBody Account account) {
        Account result = null;
        switch (account.getRole()) {
            case "STU":
                result = studentLoginService.login(account);
                break;
            case "TEA":
                result = teacherLoginService.login(account);
                break;
            case "ADMIN":
                result = adminLoginService.login(account);
                break;
        }
        return Result.success(result);
    }
}
